//
//  HMVisitorTableViewController.swift
//  weibo28
//
//  Created by 范英强 on 16/3/23.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class HMVisitorTableViewController: UITableViewController {
    
    // 是否登陆状态
    var isLogin: Bool = HMUserAccountTools.sharedTools.isLogin
    // 访客视图
    var visitorView: HMVisitorView?
    
    override func loadView() {
        
        if !isLogin{
            visitorView = HMVisitorView()
            
            // 设置登陆和注册按钮点击
            visitorView?.registerButton.addTarget(self, action: "loginClick", forControlEvents: UIControlEvents.TouchUpInside)
            visitorView?.loginButton.addTarget(self, action: "loginClick", forControlEvents: UIControlEvents.TouchUpInside)

            view = visitorView
            setBarButtonItems()
        }else{
            super.loadView()
        }
        
    }
    // 设置BarButtonItems
    func setBarButtonItems(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
    }

    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    // MARK: - 监听方法
    @objc private func loginClick(){
        let oauthVc = HMOAuthViewController()
        presentViewController(UINavigationController(rootViewController: oauthVc), animated: true, completion: nil)
    }

}
